﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;

using System.Xml;
using System.Xml.Xsl;

namespace GUI
{
    public partial class Form1 : Form
    {
        public static string traderID;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            traderID = TraderID.Text;
            if (traderID.Length == 5 && Regex.IsMatch(traderID, @"^[a-zA-Z]{5}$"))
            {
                Form2 frontEnd = new Form2();
                //this.Visible = false;
                //this.Hide();
                //frontEnd.ShowDialog();
                this.Hide();
                createXSLT();
                frontEnd.Show();      
            }
            else
            {
                MessageBox.Show("Please enter your FIVE LETTER acronym");
            }
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private static void createXSLT()
        {
            string xsltMsg = "<?xml version = \"1.0\" encoding=\"ISO-8859-1\" ?>";

            xsltMsg += "<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">";
            xsltMsg += "<xsl:output method=\"html\" />";
            xsltMsg += "<xsl:template match=\"/\">";
            xsltMsg += "<html><body><h2>Trade Printout</h2>";
            xsltMsg += "<table border=\"1\"><tr align=\"center\"><th>Service</th><th bgcolor=\"red\" width=\"50 px\">Bid ID</th><th bgcolor=\"green\" width=\"50 px\">Offer ID</th><th>Quantity</th><th>Price</th></tr>";
            xsltMsg += "<xsl:for-each select=\"TQ/Trade\">";
            xsltMsg += "<tr align=\"center\"><td><xsl:value-of select=\"Serv\"/></td><td bgcolor=\"red\"><xsl:value-of select=\"bID\"/></td><td bgcolor=\"green\"><xsl:value-of select=\"sID\"/></td><td><xsl:value-of select=\"quant\"/></td><td><xsl:value-of select=\"pr\"/></td></tr>";
            xsltMsg += "</xsl:for-each></table></body></html></xsl:template></xsl:stylesheet>";

            System.IO.File.WriteAllText(@"C:\\Temp\\A1Exchange.xslt", xsltMsg);
            //System.IO.File.WriteAllText(@"A1Exchange.xslt", xsltMsg);
        }

    }
}
